package main

import (
	"fmt"
	"net"
	"os"
	"time"
)

func main() {
	tStart := time.Now()
	conn, err := net.DialTimeout("tcp", "godoc.org:80", time.Second * 10)
	tEnd := time.Now()
	fmt.Println("连接持续时间:", time.Duration(tEnd.Sub(tStart)))
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
		return
	}
	defer conn.Close()
	fmt.Println("本地连接地址:", conn.LocalAddr())
	fmt.Println("对端连接地址:", conn.RemoteAddr())
}
